<template>
  <view
    class="content ba_img"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eeeeee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">导航仪</view>
    </view>

    <u-tabs
      class="tabs"
      :list="list1"
      @click="click"
      lineColor="#eee"
	    lineWidth="64rpx"
      :activeStyle="{
        color: '#EEEEEE',
        fontWeight: 'bold',
        transform: 'scale(1.05)',
      }"
      :inactiveStyle="{
        color: '#ADADAD',
        transform: 'scale(1)',
      }"
      :current="currentIndex"
    ></u-tabs>
    <scroll-view
      :style="{
        height: windowHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
    >
      <view class="box1">
        <navigatorS :isWhite="true" :list="{ data: list }"></navigatorS>
      </view>
    </scroll-view>
	<floatingBall></floatingBall>
  </view>
</template>

<script>
import navigatorS from "@/components/navigatorS.vue"; //导航仪
import { Region, daohangyiList } from "@/common/api/mountainSea.js";
export default {
  components: {
    navigatorS,
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      list1: [],
      list: [],
      currentIndex: 0,
      currentId: 1,
      windowHeihgt: 0,
    };
  },
  onShow() {
    this.$nextTick(() => {
     // 解决uview u-tab，下划线异常
      this.currentIndex = 0;
    });
  },
  onLoad(options) {
    if (options && options.id) {
      this.currentId = options.id;
    }
    this.getRegion();
    this.getList();
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度

    this.statusBarHeight = statusBarHeight.statusBarHeight;
    const windowHeihgt = statusBarHeight.windowHeight;

    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
          // this.windowHeihgt = statusBarHeight.windowHeight - data.height - this.statusBarHeight;
        })
        .exec();
    });
    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.windowHeihgt = windowHeihgt - sum - 50;
      });
    });
  },
  methods: {
    getRegion() {
      Region({}).then((res) => {
        console.log("resssss", res);
        this.list1 = res.data.list.map((item, index) => {
          if (item.id == this.currentId) {
            this.currentIndex = index;
          }
          return {
            ...item,
            name: item.name + "-" + item.chan,
          };
        });
      });
    },
    getList() {
      daohangyiList({
        address: this.currentId,
      }).then((res) => {
        console.log("llllistlllist", res);
        this.list = res.data.list.data;
      });
    },
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    scroll() {},
    click(e) {
      console.log("1111", e);
      this.currentIndex = e.index;
      this.currentId = e.id;
      this.getList();
    },
  },
};
</script>

<style scoped lang="scss">
.ba_img {
  position: fixed;
  top: 0;
  margin: 0;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  box-sizing: border-box;
}

.head {
  width: 100%;
  padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}

.box1 {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
}
</style>